<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程类型管理</title>
<%@ include file="../jslib/jquerylib.jsp"%>
<link href="css/style.css" type="text/css" rel="stylesheet">
<script language="jscript.encode" src="js/common.js" charset="utf-8"></script>
<script language="jscript.encode" src="js/dtree.js" charset="utf-8"></script>
<script language="jscript.encode" src="js/shape.js" charset="utf-8"></script>
<script language="jscript.encode" src="js/toppanel.js" charset="utf-8"></script>
<script language="jscript.encode" src="js/topflow.js" charset="utf-8"></script>
<script language="jscript.encode" src="js/topflowevent.js" charset="utf-8"></script>
<script language="jscript.encode" src="js/contextmenu.js" charset="utf-8"></script>
</head>
<BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style='background-image: url(image/canvasbg.gif);'>

<SCRIPT LANGUAGE="JScript">
    var _TREE;

    function DrawTree() {
        _TREE = new dTree('_TREE', 'image/');
        var num = 3, obj, i;
        var FocusColor = _FLOW.Config.ProcFocusedStrokeColor;
        _TREE.add(0, -1, ' ' + _FLOW.Text + '', 'javascript:', '', _FLOW.ID);
        _TREE.add(1, 0, '任务', 'javascript:', '', 'Procs', '', 'image/task.gif', 'image/task.gif');
        _TREE.add(2, 0, '路径', 'javascript:', '', 'Steps', '', 'image/step.gif', 'image/step.gif');
        for (i = 0; i < _FLOW.Procs.length; i++) {
            obj = _FLOW.Procs[i];
            _TREE.add(num++, 1, obj.Text, 'javascript:objFocusedOn("' + obj.ID + '");', '', obj.ID, '', 'image/obj4.gif', 'image/obj4.gif');
        }

        for (i = 0; i < _FLOW.Steps.length; i++) {
            obj = _FLOW.Steps[i];
            _TREE.add(num++, 2, obj.Text, 'javascript:objFocusedOn("' + obj.ID + '");', '', obj.ID, '', 'image/obj4.gif', 'image/obj4.gif');
        }
        treeview.innerHTML = _TREE;
    }

    function DrawDataView() {
        var idTR, idTD, arr = _FLOW.DataView();
        for (var i = dataview.rows.length - 1; i > 0; i--)
            dataview.deleteRow(i);
        for (var i = 0, u = 1; i < arr.length; i++) {
            idTR = dataview.insertRow();
            idTR.onmouseover = new Function("this.className=\"focusLine\";");
            idTR.onmouseout = new Function("this.className=\"normalLine\";");
            idTR.height = "22";
            idTD = idTR.insertCell();
            idTD.innerHTML = arr[i].ProcID + "(" + arr[i].ProcText + ")";
            idTD = idTR.insertCell();
            idTD.innerHTML = arr[i].Idx;
            idTD = idTR.insertCell();
            idTD.innerHTML = arr[i].PreProcID + "(" + arr[i].PreProcText + ")";
            idTD = idTR.insertCell();
            idTD.innerHTML = arr[i].Cond + "&nbsp;";
        }
        mergecell(dataview);
    }

    function DrawVML() {
        Canvas.innerHTML = _FLOW.ProcString();
        Canvas.innerHTML += _FLOW.StepString();
        _FLOW.getInnerObject();
        _FOCUSTEDOBJ = null;
        stuffProp();
    }

    function DrawAll() {
        //DrawTree();
        DrawVML();
        //DrawDataView();
    }

    function LoadFlow(AUrl) {
        if (AUrl == "")
            _FLOW.createNew("");
        else
            _FLOW.loadFromXML(AUrl);
        DrawAll();
        emptyLog();
    }

    function ObjSelected() {
        if (_FOCUSTEDOBJ == null) {
            alert("当前没有选中对象！--用鼠标单击流程图上的对象可以选中它");
            return false;
        }
        return true;
    }

    //[流程图]菜单处理事件
    function mnuNewFlow() {
        if (_FLOW.Modified)
            if (!confirm("当前流程图尚未保存，新建新文件将会放弃所有修改，继续新建吗？")) return;
        var flow = new TTopFlow("");
        flow.FileName = "untitled.xml";
        if (vmlOpenWin("flow.htm", flow, 350, 200)) {
            LoadFlow("");
            _FLOW.FileName = flow.FileName;
            _FLOW.Text = flow.Text;
            _FLOW.Password = flow.Password;
            DrawTree();
            delete flow;
        }
    }

    function mnuEditFlow() {
        if (vmlOpenWin("flow.htm", _FLOW, 350, 200)) {
            DrawTree();
        }
    }

    function mnuValidateFlow() {
        var s = _FLOW.validate();
        if (s == "")
            alert("校验完成，这是一个合法的流程图！");
        else
            alert(s);
    }

    function mnuOpenFlow() {
        if (_FLOW.Modified)
            if (!confirm("当前流程图尚未保存，打开新文件将会放弃所有修改，继续打开吗？")) return;
        if (vmlOpenWin("filelist.jsp", _FLOW, 450, 400))
            LoadFlow(_FLOW.FileName);
    }

    function mnuSaveFlow() {
        var typename = document.getElementById("txttypename").value;
        var typeid = document.getElementById("htypeid").value;
        if (typename == "") {
            alert('流程类型名称不能为空！');
        }
        else {
            var s = _FLOW.validate();
            if (s == "") {
            	typename = encodeURIComponent(typename);
                var result = _FLOW.SaveToXML(typename, typeid);
                alert(result);
            }
            else
                alert(s);
        }
    }

    function mnuReloadFlow() {
        if (_FLOW.Modified)
            if (!confirm("当前流程图尚未保存，重新载入将会放弃所有修改，继续重载吗？")) return;
        LoadFlow(_FLOW.FileName);
    }

    //[流程图对象]菜单处理事件
    function mnuAddProc() {
        var Proc = new TProc(_FLOW);
        if (vmlOpenWin("proc.htm", Proc, 450, 350)) {
            _FLOW.addProc(Proc);
            pushLog("addproc", Proc);
            DrawAll();
        }
    }

    function mnuAddStep() {
        var Step = new TStep(_FLOW);
        if (vmlOpenWin("step.htm", Step, 500, 350)) {
            _FLOW.addStep(Step);
            pushLog("addstep", Step);
            DrawAll();
        }
    }

    function mnuCopyProc() {
        if (!ObjSelected()) return;
        if (_FOCUSTEDOBJ.typ != "Proc") {
            alert("只有任务可以复制！");
            return;
        }
        var curProc = _FLOW.getProcByID(_FOCUSTEDOBJ.id);
        if (!confirm("确定要复制任务[" + curProc.Text + "]吗？")) return;
        var Proc = new TProc(_FLOW);
        var iID = Proc.ID;
        Proc.clone(curProc);
        Proc.ID = iID;
        Proc.X = parseInt(curProc.X) + 10;
        Proc.Y = parseInt(curProc.Y) + 10;
        _FLOW.addProc(Proc);
        pushLog("addproc", Proc);
        DrawAll();
        objFocusedOn(iID);
        mnuSetZIndex("F");
    }

    function mnuEditObj() {
        if (!ObjSelected()) return;
        if (_FOCUSTEDOBJ.typ != "Proc" && _FOCUSTEDOBJ.typ != "Step") return;
        if (_FOCUSTEDOBJ.typ == "Proc")
            editProc(_FOCUSTEDOBJ.id);
        else
            editStep(_FOCUSTEDOBJ.id);
    }

    function mnuDelObj() {
        if (ObjSelected()) deleteObj(_FOCUSTEDOBJ.id);
    }

    function mnuSetZIndex(Act) {
        if (!ObjSelected()) return;
        if (_FOCUSTEDOBJ.typ != "Proc" && _FOCUSTEDOBJ.typ != "Step") return;
        if (_FOCUSTEDOBJ.typ == "Proc")
            var obj = _FLOW.getProcByID(_FOCUSTEDOBJ.id);
        else
            var obj = _FLOW.getStepByID(_FOCUSTEDOBJ.id);
        var oldValue = obj.zIndex;
        if (Act == "F")
            _FLOW.brintToFront(obj);
        else
            _FLOW.sendToBack(obj);
        _FOCUSTEDOBJ.style.zIndex = obj.zIndex;
        pushLog("editprop", { "obj": obj, "prop": "zIndex", "_old": oldValue, "_new": obj.zIndex });
    }

    //[系统菜单]处理事件
    function mnuOption() {
        if (vmlOpenWin("option.htm", _FLOW.Config, 510, 510)) {
            DrawAll();
        }
    }

    function mnuDemo() {
        var tmpwin = window.open("demo.htm");
        tmpwin.focus();
    }

    function mnuFileMgr() {
        vmlOpenWin("filemgr.jsp", "", 450, 400);
    }
    
    function mnuDuiq() {
        var procs = _FLOW.Procs;
        for(var i =0;i<procs.length;i++)
        {
            var proc1 = procs[i];
        	for(var j=i+1;j<procs.length;j++)
        	{
        		var proc2 = procs[j];
        		if (Math.abs(parseInt(proc1.X)-parseInt(proc2.X))<30)
        		{
        			 proc2.X = proc1.X;
        		}
        		if (Math.abs(parseInt(proc1.Y)-parseInt(proc2.Y))<30)
        		{
        			proc2.Y = proc1.Y;
        		}
        	}
        }
        DrawAll();
    }

    function mnuAbout() {
        vmlOpenWin("about.jsp", "", 480, 400);
    }

    function mnuExit() {
        if (confirm("确定要退出本系统吗？")) {
            window.opener = null;
            window.close();
        }
    }

    function mnuSetZoom(Act) {
        var rate = Act == "in" ? 0.2 : -0.2;
        var newzoom = _ZOOM + rate;
        if (newzoom > 2) return;
        if (newzoom < 0.2) return;
        changeZoom(newzoom);
        document.all("zoomshow").value = _ZOOM;
    }

    function changeZoom(v) {
        _ZOOM = parseFloat(parseFloat(v).toFixed(2));
        Canvas.style.zoom = _ZOOM;
    }

    function mnuTurnToolbox() {
        tbxToolbox.VisibleEx = !tbxToolbox.VisibleEx;
        tbxToolbox.InnerObject.style.display = tbxToolbox.VisibleEx ? "block" : "none";
        document.all.mnu_win_toolbox.innerHTML = (tbxToolbox.VisibleEx ? "隐藏" : "显示") + "工具箱";
    }

    function mnuTurnPropbox() {
        tbxPropbox.VisibleEx = !tbxPropbox.VisibleEx;
        tbxPropbox.InnerObject.style.display = tbxPropbox.VisibleEx ? "block" : "none";
        document.all.mnu_win_propbox.innerHTML = (tbxPropbox.VisibleEx ? "隐藏" : "显示") + "属性框";
    }

    function mnuTurnObjView() {
        tbxObjView.VisibleEx = !tbxObjView.VisibleEx;
        tbxObjView.InnerObject.style.display = tbxObjView.VisibleEx ? "block" : "none";
        document.all.mnu_win_objview.innerHTML = (tbxObjView.VisibleEx ? "隐藏" : "显示") + "对象视图";
    }

    function mnuTurnDataView() {
        tbxDataView.VisibleEx = !tbxDataView.VisibleEx;
        tbxDataView.InnerObject.style.display = tbxDataView.VisibleEx ? "block" : "none";
        document.all.mnu_win_dataview.innerHTML = (tbxDataView.VisibleEx ? "隐藏" : "显示") + "数据视图";
    }

    function openChild(item) {
    	if (item=='txtReader')
    	{
    		var users = window.showModalDialog("/resource/choose/chooseAllUser.jsp", window, "dialogWidth:1000px;status:no;dialogHeight:500px");
        	if (users != null) {
        		var userIds = [];
                var userNames = [];
                for(var i=0;i<users.length;i++){
                    userIds.push(users[i]['userid']);
                    userNames.push(users[i]['username']);
                }
	            setPropReader(userIds.join(),userNames.join());
        	}
    	}
    	if (item=='txtRole')
    	{
    		var roles = window.showModalDialog("/resource/choose/selectRole.jsp", window, "dialogWidth:665px;status:no;dialogHeight:500px");
        	if (roles != null) {
        		var roleIds = [];
                var roleNames = [];
                for(var i=0;i<roles.length;i++){
                    roleIds.push(roles[i]['roleid']);
                    roleNames.push(roles[i]['rolename']);
                }
	            setPropRole(roleIds.join(),roleNames.join());
        	}
    	}
        else if (item=='txtForm')
        {
        	var k = window.showModalDialog("FormSelect.jsp?type=flow", window, "dialogWidth:820px;status:no;dialogHeight:500px");
	        if (k != null) {
	            var temp = document.getElementById(item);
	            temp.value = k;
	            setPropForm(temp);
	        }
        }
    }
    
    <%String filename = "";
      if (request.getParameter("filename")!=null&&!request.getParameter("filename").equals(""))
      {
    	  filename  = new String(request.getParameter("filename").getBytes("ISO8859_1"),"utf-8");
      }
      
      String flowname = "";
      if (request.getParameter("flowname")!=null&&!request.getParameter("flowname").equals(""))
      {
    	  flowname  = new String(request.getParameter("flowname").getBytes("ISO8859_1"),"utf-8");
      }
      %>
      
    function openSubFlow(childfilename) {
    	if (childfilename=="null")
    	{
    		alert('该节点无子流程！')
    	}
    	else
    	{
    		window.open ("FlowTypeAddView.jsp?filename="+childfilename,'子流程','height=650,width=1050,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no') 
    	}
    }
    
    function mnuViewObj() {
        if (ObjSelected()) 
        {
        	var curProc = _FLOW.getProcByID(_FOCUSTEDOBJ.id);
        	var childfilename = curProc.childfilename;
        	if (childfilename==null)
    		{
    			alert('该节点无子流程！')
    		}
    		else
    		{
    			window.open ("FlowTypeAddView.jsp?filename="+childfilename,'子流程','height=650,width=1050,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no') 
    		} 
        }
    }
    //-->
</SCRIPT>
<input type="hidden" value="<%=request.getParameter("id")!=null?request.getParameter("id"):""%>" id="htypeid" />
<div style='left:0px;top:0px;width:100%;height:100%;position:absolute;z-index:-1000' id="Canvas"></div>
<v:rect class="toolui" style="display:none" id="_rectui">
<v:Stroke dashstyle="dashdot"/>
</v:rect>
<v:rect class="toolui" style="display:none" fillcolor="#CCCCCC" id="_fillrectui">
<v:Stroke dashstyle="dashdot"/>
</v:rect>
<v:roundrect class="toolui" style="display:none;left:0px;top:0px;width:60px;height:50px;" id="_roundrectui">
<v:Stroke dashstyle="dashdot"/>
</v:roundrect>
<v:shape type="#diamond" class="toolui" style="display:none;left:0px;top:0px;width:60px;height:50px;" strokeweight="1px" id="_diamondui">
<v:Stroke dashstyle="dashdot"/>
</v:shape>
<v:oval class="toolui" style="display:none;left:0px;top:0px;width:60px;height:50px;" id="_ovalui">
<v:Stroke dashstyle="dashdot"/>
</v:oval>
<v:line class="toolui" style="display:none" from="0,0" to="100,0" id="_lineui">
<v:Stroke dashstyle="dashdot" StartArrow="" EndArrow="Classic"/>
</v:line>
<SCRIPT LANGUAGE="JavaScript">

<!--
    function NavBrush_onClick(obj) {
        //清除所有的ButtonClass
        var objs = document.all("tbxToolbox_btn");
        for (var i = 0; i < objs.length; i++)
            objs[i].className = "bon2";
        obj.className = "bon1";
        _TOOLTYPE = obj.cType;
    }

    

    LoadFlow("<%=request.getParameter("filename")!=null?request.getParameter("filename"):""%>");
//-->
</SCRIPT>


</BODY>
</html>